﻿using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

namespace DimensionsHelper.LanguageService.Syntax;

public class SourceIdentifier : PreExpression
{
    internal SourceIdentifier(SourceNode? parent) : base(parent, SyntaxKinds.Identifier)
    {
    }


    public static SourceIdentifier DefaultIdentifier { get; } = new(null);


    public static bool IsNullOrDefaultIdentifier([NotNullWhen(false)] SourceIdentifier? identifier)
    {
        return identifier == null || ReferenceEquals(identifier, DefaultIdentifier);
    }
}

public static partial class NodeFactory
{
    public static SourceIdentifier CreateSourceIdentifier(SourceNode? parent, string identifierName)
    {
        SourceIdentifier node = new(parent);
        node.Update(identifierName);
        return node;
    }


    public static SourceIdentifier CreateSourceIdentifier(SourceNode source)
    {
        Debug.Assert(source.IsNode(SyntaxKinds.Identifier));
        SourceIdentifier node = new(null);
        node.UpdateFrom(source);
        node.SetFlags(source.GetFlags());
        return node;
    }
}